<?php
/**
 * @Author: Xu Liu email:2867557054@qq.com
 * @Date:   2016-12-15 13:31:33
 * @Last Modified by:   Xu Liu
 * @Last Modified time: 2018-01-03 22:35:22
 */
if (!defined('IN_ADMINCP') || !defined('IN_DISCUZ')) {
    exit('Access Denied');
}
class MtempContrl
{
    public function index()
    {
        global $_G;
        $template = C::t('common_setting')->fetch('jameson_read');
        $kuandu   = (int) C::t('common_setting')->fetch('jamesonreadwidth');
        // 所有模板模板
        $hastemp = array();
        $dir     = dir('./source/plugin/jameson_read/template');
        while (false !== ($entry = $dir->read())) {
            if (preg_match("/^[a-zA-Z0-9_\-]+$/i",$entry) && ($entry != 'touch') && is_dir('./source/plugin/jameson_read/template/' . $entry) && is_file('./source/plugin/jameson_read/template/' . $entry . '/' . $entry . '.jpg')) {
                $hastemp[] = $entry;
            }
        }
        if (!$template || !in_array($template, $hastemp) || !is_dir('./source/plugin/jameson_read/template/' . $template)) {
            $template = ($template == 'boot') ? '163' : $template;
        }
        include template('jameson_read:mtemp_index');
    }
    public function post()
    {
        global $_G;
        if (submitcheck('editsubmit')) {
            if ($template = trim($_GET['template'])) {
                // 查询所选模板的风格id
                C::t('common_setting')->update('jameson_read', daddslashes($template));
            }
            $kuandu = intval($_GET['pckuandu']);
            C::t('common_setting')->update('jamesonreadwidth', $kuandu);
            cpmsg(lang('plugin/jameson_read', 'gengxinchenggong'), 'action=plugins&operation=config&do=' . $_GET['do'] . '&identifier=jameson_read&pmod=jameson_read&contrl=mtemp&act=index', 'succeed');
        } else {
            cpmsg(lang('plugin/jameson_read', 'laiyuanfeifa'), 'action=plugins&operation=config&do=' . $_GET['do'] . '&identifier=jameson_read&pmod=jameson_read&contrl=mtemp&act=index', 'error');
        }
    }
}